#ifndef AVALON_CODEDWRITER_HPP
#define AVALON_CODEDWRITER_HPP
#include "Avalon/Base/Handle.hpp"
#include "Avalon/Codecs/Codecs.hpp"
#include "Avalon/IO/Writer.hpp"

namespace Avalon {
namespace Codecs {

  /*! \class CodedWriter
   *  \brief Writes coded data using a Decoder.
   *  \author Kamal Mansouri <kranar@hotmail.com>
   */
  class CodedWriter : public IO::Writer {
    public:

      //! Creates a CodedWriter.
      /*!
        \param destination The destination to write to.
        \param encoder The Encoder to use.
        \param encodeInPlace Set to <code>true</code> to encode in place.
      */
      CodedWriter(Carry<IO::Writer> destination, Encoder* encoder,
        bool encodeInPlace = false);

      virtual ~CodedWriter();

      virtual Threading::Async<void>::Ptr Write(const void* data, int size);

      virtual Threading::Async<void>::Ptr Write(const IO::Buffer& data);

    private:
      Handle<IO::Writer> m_destination;
      boost::scoped_ptr<Encoder> m_encoder;
      bool m_encodeInPlace;
  };
}
}

#endif // AVALON_CODEDWRITER_HPP
